package com.ocss.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ocss.common.annotation.Log;
import com.ocss.common.core.controller.BaseController;
import com.ocss.common.core.domain.AjaxResult;
import com.ocss.common.enums.BusinessType;
import com.ocss.system.domain.OcssTeacher;
import com.ocss.system.service.IOcssTeacherService;
import com.ocss.common.utils.poi.ExcelUtil;
import com.ocss.common.core.page.TableDataInfo;

/**
 * 教师信息Controller
 *
 * @author ligen
 * @date 2024-03-06
 */
@RestController
@RequestMapping("/system/teacher")
public class OcssTeacherController extends BaseController {
    @Autowired
    private IOcssTeacherService ocssTeacherService;

    /**
     * 查询所有教师信息
     */
//    @PreAuthorize("@ss.hasPermi('system:teacher:list')")
    @GetMapping("/listAll")
    public AjaxResult listAll(OcssTeacher ocssTeacher) {
        List<OcssTeacher> list = ocssTeacherService.selectOcssTeacherList(ocssTeacher);
        return success(list);
    }

    /**
     * 查询教师信息列表
     */
//    @PreAuthorize("@ss.hasPermi('system:teacher:list')")
    @GetMapping("/list")
    public TableDataInfo list(OcssTeacher ocssTeacher) {
        startPage();
        List<OcssTeacher> list = ocssTeacherService.selectOcssTeacherList(ocssTeacher);
        return getDataTable(list);
    }

    /**
     * 导出教师信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:teacher:export')")
    @Log(title = "教师信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OcssTeacher ocssTeacher) {
        List<OcssTeacher> list = ocssTeacherService.selectOcssTeacherList(ocssTeacher);
        ExcelUtil<OcssTeacher> util = new ExcelUtil<OcssTeacher>(OcssTeacher.class);
        util.exportExcel(response, list, "教师信息数据");
    }

    /**
     * 获取教师信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:teacher:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(ocssTeacherService.selectOcssTeacherById(id));
    }

    /**
     * 新增教师信息
     */
    @PreAuthorize("@ss.hasPermi('system:teacher:add')")
    @Log(title = "教师信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OcssTeacher ocssTeacher) {
        int row = ocssTeacherService.insertOcssTeacher(ocssTeacher);

        if (row > 0) {
            return success("添加成功");
        }

        return error("添加失败，用户可能已存在");
    }

    /**
     * 修改教师信息
     */
    @PreAuthorize("@ss.hasPermi('system:teacher:edit')")
    @Log(title = "教师信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OcssTeacher ocssTeacher) {
        return toAjax(ocssTeacherService.updateOcssTeacher(ocssTeacher));
    }

    /**
     * 删除教师信息
     */
    @PreAuthorize("@ss.hasPermi('system:teacher:remove')")
    @Log(title = "教师信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(ocssTeacherService.deleteOcssTeacherByIds(ids));
    }
}
